﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 8/29/2009
 * Time: 12:57 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using Buaya.Model;

namespace Buaya.Gui
{
	/// <summary>
	/// Description of CompanyForm.
	/// </summary>
	public partial class CompanyForm : BaseForm
	{
		public CompanyForm(Company c)
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			Model = c;
		}
		
		protected override void OnModelChanged(EventArgs e)
		{
			base.OnModelChanged(e);
			Company c = Model as Company;
			textBoxName.Text = c.Name;
			richTextBoxAddress.Text = c.Address;
			comboBoxCountry.SelectedIndex = c.Country;
			textBoxPhone.Text = c.Phone;
			textBoxFax.Text = c.Fax;
			textBoxEmail.Text = c.Email;
			textBoxWebsite.Text = c.Website;
			textBoxLegalName.Text = c.LegalName;
			if (c.LegalAddress != null) {
				textBoxStreet1.Text = c.LegalAddress.Street1;
				textBoxStreet2.Text = c.LegalAddress.Street2;
				textBoxCity.Text = c.LegalAddress.City;
				textBoxZip.Text = c.LegalAddress.Zip;
			}
			comboBoxState.SelectedIndex = c.State;
			comboBoxLegalCountry.SelectedIndex = c.LegalCountry;
			comboBoxFiscalYear.SelectedIndex = c.FiscalYear;
			comboBoxTaxYear.SelectedIndex = c.TaxYear;
			comboBoxIncomeTaxForm.SelectedIndex = c.IncomeTaxForm;
			textBoxEIN.Text = c.EIN;
			textBoxSSN.Text = c.SSN;
			textBoxPayrollContact.Text = c.PayrollContact;
			textBoxPayrollContactTitle.Text = c.PayrollContactTitle;
			textBoxPayrollContactPhone.Text = c.PayrollContactPhone;
		}
		
		void ButtonOkClick(object sender, EventArgs e)
		{
			Company c = Model as Company;
			c.Name = textBoxName.Text;
			c.Address = richTextBoxAddress.Text;
			c.Country = comboBoxCountry.SelectedIndex;
			c.Phone = textBoxPhone.Text;
			c.Fax = textBoxFax.Text;
			c.Email = textBoxEmail.Text;
			c.Website = textBoxWebsite.Text;
			c.LegalName = textBoxLegalName.Text;
			c.LegalAddress = new Address(textBoxStreet1.Text, textBoxStreet2.Text, textBoxCity.Text, "", textBoxZip.Text, "");
			c.State = comboBoxState.SelectedIndex;
			c.LegalCountry = comboBoxLegalCountry.SelectedIndex;
			c.FiscalYear = comboBoxFiscalYear.SelectedIndex;
			c.TaxYear = comboBoxTaxYear.SelectedIndex;
			c.IncomeTaxForm = comboBoxIncomeTaxForm.SelectedIndex;
			c.EIN = textBoxEIN.Text;
			c.SSN = textBoxSSN.Text;
			c.PayrollContact = textBoxPayrollContact.Text;
			c.PayrollContactTitle = textBoxPayrollContactTitle.Text;
			c.PayrollContactPhone = textBoxPayrollContactPhone.Text;
			SessionFacade.SaveOrUpdateCompany(c);
			Close();
		}
		
		void ButtonCancelClick(object sender, EventArgs e)
		{
			Close();
		}
		
		void ButtonShipToAddressClick(object sender, EventArgs e)
		{
			MainForm.Instance.AddDialog(new ShipToInformationForm(Model as Company));
		}
	}
}
